function initbody(){
	ind.init();
}
var badgearr = {};
var ind = {
	init:function(){
		opentabs= [];
		tabsarr = {};
		objcont = $('#content_allmainview');
		objtabs = $('#tabs_title');
		this.resizewh();
		$(window).resize(this.resizewh);
		if(homers)homers  = js.decode(homers);
		if(!homers)homers = {name:'首页',icons:'home',num:'home',url:'index,home',hideclose:true}
		addtabs(homers);
		this.firstmenu();
		
		$('#toplogo').click(function(){
			ind.hideleft();
		});
		this.showfirstmenu();
		$('#mainsou').keydown(function(e){
			if(e.keyCode==13){
				ind.gotosou();
			}
		});
	},
	oldval:'',
	gotosou:function(){
		var val = get('mainsou').value;
		if(this.oldval==val)return;
		if(!changetabs('word')){
			this.clickmenu(1,-1);
		}else{
			mainword.search();
		}
		this.oldval = val;
	},
	showfirstmenu:function(){
		var da = [];
		da.push({name:'分区管理',icon:'hdd',url:'main,fenqu',num:'fenqu'});
		da.push({name:'文件管理',icon:'folder-close-alt',url:'main,word',num:'word'});
		da.push({name:'共享文件',icon:'share',url:'main,word,shate',num:'share'});
		if(admintype==1)da.push({name:'系统管理',icon:'cog','url':'?m=manage'});
		da.push({name:'手机版',icon:'tablet','url':'?d=we',num:'mobile'});
		//da.push({name:'回收站',icon:'trash'});
		this.showmenus(da);
	},
	resizewh:function(){
		var _lw = 0;
		if(get('indexmenu')){
			_lw = $('#indexmenu').width();
			if(get('indexmenu').style.display=='none'){
				_lw = 0;
			}
		}
		var w = winWb()-_lw;
		var h = winHb(),_ht=0;
		if(get('topheaderid'))_ht=get('topheaderid').offsetHeight;
		var meih = h-60-get('souheiht').offsetHeight;
		$('#indexmenushow').css('height',''+meih+'px');
		viewwidth  = w;
		viewheight = h-60;
		$('#indexcontent').css({width:''+viewwidth+'px',height:''+(viewheight)+'px'});
		viewheight-=22;
	},
	hideleft:function(){
		$('#indexmenu').toggle();
		this.resizewh();
	},
	firstmenu:function(bo){
		if(!bo){
			if(!get('topmenuid0'))return;
			var o1   = $('#topmenuid0');
			var pid  = o1.attr('pmenuid');
		}else{
			var o1   = $(bo);
			var pid  = o1.attr('pmenuid');
		}
		$('td[pmenuid]').removeClass('zhuactive');
		o1.addClass('zhuactive');
		var s1 = o1.attr('title'),ico = o1.attr('icon');
		if(ico)s1='<i class="icon-'+ico+'"></i> '+s1+'';
		$('#menulisttop').html(s1);
		this.showmenu(pid);
	},
	showmenu:function(pid){
		if(this.menupid == pid)return;
		this.menupid = pid;
		$('#indexmenushow').html('<div style="padding:30px;" align="center"><img src="images/mloading.gif"></div>');
		js.ajax({
			url:'?m=index&a=getmenu',
			data:{pid:pid},
			dataType:'json',
			success:function(da){
				ind.showmenus(da);
			}
		});
	},
	showmenus:function(da){
		this.menudata = da;
		var str = '',isd,sda,i,j,bh;
		for(i=0;i<da.length;i++){
			sda = da[i].menusub;
			isd = 'bookmark-empty';
			bh  = da[i].num;
			if(da[i].icon)isd = da[i].icon;
			str+='<div onclick="ind.clickmenu('+i+',-1)" class="leftmenu"><i class="icon-'+isd+'"></i> '+da[i].name+'';
			if(sda && sda.length>0){
				if(badgearr['pid'+da[i].id+''])str+='<span style="color:red" id="pidshow_'+da[i].id+'">●</span>';
				str+='<font><i class="icon-angle-right"></i></font>';
			}else{
				if(bh && badgearr[bh])str+='<span style="margin-left:3px" class="badge" id="stotal_'+bh+'">'+badgearr[bh]+'</span>';
			}
			str+='</div>';
			if(sda && sda.length>0){
				str+='<div style="display:none" id="submenuss'+da[i].id+'">';
				for(j=0;j<sda.length;j++){
					isd = 'bookmark-empty';
					if(sda[j].icon)isd = sda[j].icon;
					bh  = sda[j].num;
					str+='<div onclick="ind.clickmenu('+i+','+j+')" class="leftmenu_sub"><i class="icon-'+isd+'"></i> '+sda[j].name+'';
					if(bh && badgearr[bh])str+='<span style="margin-left:3px" class="badge" id="stotal_'+bh+'">'+badgearr[bh]+'</span>';
					str+='</div>';
				}
				str+='</div>';
			}
		}
		$('#indexmenushow').html(str);
	},
	clickmenu:function(i,j){
		var da = this.menudata[i];
		if(j>-1)da = da.menusub[j];
		if(da.menusub && da.menusub.length>0){
			$('#submenuss'+da.id+'').toggle();
		}else{
			if(!da.icon)da.icon='';
			if(!da.num)da.num = 'num'+da.id+'';
			if(!da.url){
				js.msgerror('没有设置地址');
				return;
			}
			addtabs({name:da.name,url:da.url,num:da.num,icons:da.icon});
		}
	},
	hidebadge:function(bh){
		if(!bh)return;
		if(get('stotal_'+bh+'')){
			$('#stotal_'+bh+'').remove();
			badgearr[bh]=false;
			var pids = badgearr[bh+'pid'];
			if(pids){
				var pidsa = pids.split(','),i,pid;
				for(i=0;i<pidsa.length;i++){
					pid = pidsa[i];
					if(pid>0){
						badgearr['pid'+pid+'']--;
						if(badgearr['pid'+pid+'']<=0)$('#pidshow_'+pid+'').remove();
					}
				}
			}
			console.log(badgearr);
		}
	}
}

//添加选择卡
function addtabs(a){
	var url = a.url,
		num	= a.num;
	ind.hidebadge(num);	
	if(isempt(url))return false;
	if(num=='mobile'){
		js.open(url,320,500);
		return;
	}
	if(url.indexOf('?')==0){
		window.open(url);
		return;
	}
	nowtabs = a;
	if(changetabs(num))return true;
	var s = '<td temp="tabs" nowrap onclick="changetabs(\''+num+'\',1)" id="tabs_'+num+'" class="active"><font>';
	if(a.icons)s+='<i class="icon-'+a.icons+'"></i>  ';
	s+=a.name+'</font>';
	if(!a.hideclose)s+='<span onclick="closetabs(\''+num+'\')"><img src="images/del.png" width="12" height="12"></span>';
	s+='</td>';
	objtabs.append(s);
	
	var rand = js.getrand(),i,oi=2,
		ura	= url.split(','),
		dir	= ura[0],
		mode= ura[1];
	url =''+dir+'/'+mode+'/rock_'+mode+'';
	if(ura[2]){
		if(ura[2].indexOf('=')<0){
			oi=3;
			url+='_'+ura[2]+'';
		}
	}
	var urlpms= '';
	for(i=oi;i<ura.length;i++){
		var nus	= ura[i].split('=');
		urlpms += ',"'+nus[0]+'":"'+nus[1]+'"';
	}
	if(urlpms!='')urlpms = urlpms.substr(1);
	var bgs  = '<div id="mainloaddiv" style="width:'+viewwidth+'px;height:'+viewheight+'px;overflow:hidden;background:#000000;color:white;filter:Alpha(opacity=20);opacity:0.2;z-index:3;position:absolute;left:0px;line-height:'+viewheight+'px;top:0px;" align="center"><img src="images/mloading.gif"  align="absmiddle">&nbsp;加载中...</div>';
	$('#indexcontent').append(bgs);
	a.urlpath = url+'.php';
	objcont.append('<div temp="content" id="content_'+num+'"></div>');
	$.ajax({
		url:'?m=index&a=getshtml&surl='+jm.base64encode(url)+'&num='+num+'&urlpms='+jm.base64encode(urlpms)+'',
		type:'get',
		success: function(da){
			$('#mainloaddiv').remove();
			var s = da;
				s = s.replace(/\{rand\}/gi, rand);
				s = s.replace(/\{mode\}/gi, mode);
				s = s.replace(/\{dir\}/gi, dir);
				s = s.replace(/\{params\}/gi, 'var params={'+urlpms+'};');
			var obja = $('#content_'+num+'');
			if(num!='home')s='<div style="background:white;overflow:auto;border-radius:5px"><div style="padding:10px">'+s+'</div></div>';
			obja.html(s);
		},
		error:function(){
			$('#mainloaddiv').remove();
			var s = 'Error:加载出错喽,'+url+'';
			$('#content_'+num+'').html(s);
		}
	});
	tabsarr[num] = a;
	return false;
}

var coloebool = false;
function closetabs(num){
	tabsarr[num] = false;
	$('#content_'+num+'').remove();
	$('#tabs_'+num+'').remove();
	if(num == nowtabs.num){
		var now ='home',i,noux;
		for(i=opentabs.length-1;i>=0;i--){
			noux= opentabs[i];
			if(get('content_'+noux+'')){
				now = noux;
				break;
			}
		}
		changetabs(now);
	}
	coloebool = true;
	setTimeout('coloebool=false',10);
}

function changetabs(num,lx){
	if(coloebool)return;
	if(!lx)lx=0;
	$("div[temp='content']").hide();
	$("[temp='tabs']").removeClass();
	var bo = false;
	if(get('content_'+num+'')){
		$('#content_'+num+'').show();
		$('#tabs_'+num+'').addClass('active');
		nowtabs = tabsarr[num];
		if(typeof(nowtabs.onshow)=='function')nowtabs.onshow();
		bo = true;
	}
	opentabs.push(num);
	return bo;
}